<template>
	<view>
		<u-navbar placeholder fixed autoBack border title="工资专户"></u-navbar>
		<d-select :options="options" @query="search"></d-select>

		<view class="d-p-30">
			<view class="card d-p-30">
				<view class="d-flex d-m-b-30"><view class="sub-title d-font-30 d-flex-1" style="color: #0882F3;">专户统计</view></view>
				<chart :acc="acc"></chart>
			</view>
			<view class="card d-p-30 d-m-t-30">
				<view class="d-flex d-m-b-30">
					<view class="sub-title d-font-30" style="color: #0882F3;">银行专户余额</view>
					<text class="d-font-24 d-m-l-10" style="color: #ADB4BD;">(万元)</text>
				</view>
				<bankChart :bank="bank"></bankChart>
			</view>

			<view class="d-font-32 d-m-t-40" style="font-weight: bold;color: #323334;">专户列表</view>
			<view class="card d-p-30 d-m-t-30" v-for="(item, index) in list" :key="index" @click="specialItemDetail(item.id)">
				<view class="d-flex">
					<view class="d-font-28 d-flex-1" style="color: #151C24;font-weight: bold;">{{ item.zhmc }}</view>
				</view>
				<view class="d-flex d-m-t-20 d-font-24" style="color: #5D6672;">
					<view class="d-flex d-flex-1">
						<text>施工单位</text>
						<text class="d-m-l-20 d-flex-1 " style="color: #162233;">{{ item.sgdwmc }}</text>
					</view>
				</view>
				<view class="d-flex d-m-t-20 d-font-24" style="color: #5D6672;">
					<view class="d-flex-1 d-flex">
						<text>项目名称</text>
						<text class="d-m-l-20 d-flex-1 u-line-1" style="color: #162233;">{{ item.xmmc }}</text>
					</view>
				</view>
				<view class="d-flex d-m-t-20 d-font-24" style="color: #5D6672;">
					<view class="d-flex d-flex-1">
						<text>开户银行</text>
						<text class="d-m-l-20 d-flex-1 u-line-1" style="color: #162233;">{{ item.khh }}</text>
					</view>
				</view>
				<view class="d-flex d-m-t-20 d-font-24" style="color: #5D6672;">
					<view class="d-flex-1 d-flex">
						<text>项目类型</text>
						<text class="d-m-l-20 d-flex-1 u-line-1" style="color: #162233;">{{ item.xmtype }}</text>
					</view>
					<view class="d-flex" style="width: 260rpx; d-flex">
						<text>专户余额</text>
						<text class="d-m-l-20 d-flex-1 u-line-1" style="color: #162233;">{{ item.zhyeNew || 0 }}</text>
					</view>
				</view>
				<view class="d-flex d-m-t-20 d-font-24" style="color: #5D6672;">
					<view class="d-flex-1 d-flex">
						<text>属地名称</text>
						<text class="d-m-l-20 d-flex-1 u-line-1" style="color: #162233;">{{ item.districtName }}</text>
					</view>
				</view>
			</view>
			<template v-if="!list || list.length <= 0">
				<view><u-empty icon="/static/image/none.png" :text="'暂无数据'"></u-empty></view>
			</template>
		</view>
	</view>
</template>

<script>
import chart from './components/chart.vue';
import bankChart from './components/bankChart.vue';
import { accStatistics, dictList, appNation, accbByBank, accounts } from '../../../common/api.js';
export default {
	components: {
		chart,
		bankChart
	},
	data() {
		return {
			options: [],
			acc: null,
			bank: null,
			query: {},
			list: [],
			pageNum: 1,
			pageSize: 20,
			pageLast: 1
		};
	},
	onLoad() {
		this.init();
	},
	onReachBottom() {
		if (this.pageLast > this.pageNum) {
			++this.pageNum;
			this.getList().then(e => {
				this.list = this.list.concat(e.data);
			});
		}
	},
	methods: {
		init() {
			let district, bankType;
			appNation()
				.then(e => {
					district = e.data.map(e => {
						return {
							id: e.districtId,
							label: e.districtName
						};
					});
				})
				.then(() => {
					return dictList({
						type: 'yhdm'
					}).then(e => {
						bankType = e.data.map(e => {
							return {
								id: e.dictValue,
								label: e.dictLabel
							};
						});
					});
				})
				.then(() => {
					this.options = [
						{
							label: '属地',
							name: 'districtId',
							children: district
						},
						{
							label: '开户银行名称',
							name: 'bankType',
							children: bankType
						}
					];
				})
				.then(() => {
					this.getData();
				});
		},
		getData() {
			accStatistics({
				params: {
					deptId: this.$user.deptId,
					...this.query
				}
			}).then(e => {
				this.acc = e.data;
			});
			accbByBank({
				params: {
					deptId: this.$user.deptId,
					...this.query
				}
			}).then(e => {
				this.bank = e.data;
			});
			this.pageNum = 1;
			this.getList().then(e => {
				this.list = e.data;
				this.pageLast = Math.ceil(e.total / this.pageSize);
			});
		},
		getList() {
			return accounts({
				params: {
					deptId: this.$user.deptId,
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					...this.query
				}
			});
		},
		search(e) {
			this.query = e;
			this.getData();
		},
		specialItemDetail(id) {
			uni.$u.route({
				url: '/pages/index/special/specialItemDetail',
				params: {
					id: id
				}
			});
		}
	}
};
</script>

<style lang="scss">
.card {
	box-shadow: 0rpx 5rpx 10rpx rgba(0, 0, 0, 0.05);
	border-radius: 10rpx;
	background-color: #ffffff;
	.sub-title {
		position: relative;
		padding-left: 20rpx;
		&::before {
			content: '';
			position: absolute;
			left: 0;
			top: 0;
			width: 8rpx;
			height: 22rpx;
			background: #13a4fe;
			border-radius: 4rpx;
			bottom: 0;
			margin: auto;
		}
	}
}
page {
	background-color: #fbfcfc;
}
</style>
